﻿using System;
using System.Collections.Generic;

using System.Text;

namespace System.Qizx.Xml
{
    /*******************************/
    /// <summary>
    /// Manages the target where the result of the transformation will be saved.
    /// </summary>
    public class GenericResult : BasicResult
    {
        /// <summary>
        /// Represents the type of the result.
        /// </summary>
        public enum TYPE { Uri, Stream, Writer, File, Null }

        private string id;
        private string name;
        private System.IO.StreamWriter writer;
        private System.IO.Stream stream;
        private TYPE type;

        /// <summary>
        /// Basic Constructor for the class.
        /// </summary>
        public GenericResult()
        {
            id = null;
            name = "";
            writer = null;
            stream = null;
            type = TYPE.Null;
        }

        /// <summary>
        ///  Gets and sets the Id of the GenericResultSupport instance.
        /// </summary>
        public virtual string Id
        {
            get
            {
                return this.id;
            }
            set
            {
                this.id = value;
                this.name = value;
                this.writer = null;
                this.stream = null;
                this.type = TYPE.Uri;
            }
        }

        /// <summary>
        /// Gets and sets the StreamWriter associated to the instance.
        /// </summary>
        public virtual System.IO.StreamWriter Writer
        {
            get
            {
                return this.writer;
            }
            set
            {
                this.id = null;
                this.name = "";
                this.writer = value;
                this.type = TYPE.Writer;
            }
        }

        /// <summary>
        /// Gets and sets the Stream associated to the instance.
        /// </summary>
        public virtual System.IO.Stream Stream
        {
            get
            {
                return this.stream;
            }
            set
            {
                this.id = null;
                this.name = "";
                this.stream = value;
                this.type = TYPE.Stream;
            }
        }

        /// <summary>
        /// Gets and sets the type of the instance.
        /// </summary>
        public virtual TYPE Type
        {
            get
            {
                return type;
            }
            set
            {
                type = value;
            }
        }

        /// <summary>
        /// Creates a new instance from the specified Uri.
        /// </summary>
        /// <param name="Uri">The Uri to be used.</param>
        public GenericResult(string Uri)
        {
            this.id = Uri;
            this.name = Uri;
            this.writer = null;
            this.stream = null;
            this.type = TYPE.Uri;
        }

        /// <summary>
        /// Creates a new instance from the specified StreamWriter.
        /// </summary>
        /// <param name="writer">The StreamWriter instance to be used.</param>
        public GenericResult(System.IO.StreamWriter Writer)
        {
            this.id = null;
            this.name = "";
            this.writer = Writer;
            this.stream = null;
            this.type = TYPE.Writer;
        }

        /// <summary>
        /// Creates a new instance from the specified Stream.
        /// </summary>
        /// <param name="stream">The Stream instance to be used.</param>
        public GenericResult(System.IO.Stream Stream)
        {
            this.id = null;
            this.name = "";
            this.writer = new System.IO.StreamWriter(Stream);
            this.stream = Stream;
            this.type = TYPE.Stream;
        }

        /// <summary>
        /// Creates a new instance from the specified FileInfo.
        /// </summary>
        /// <param name="file">The FileInfo instance to be used.</param>
        public GenericResult(System.IO.FileInfo File)
        {
            this.id = File.FullName;
            this.name = File.FullName;
            this.writer = null;
            this.stream = null;
            this.type = TYPE.File;
        }
    }
}
